package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.bind.DefaultValue;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping(("/nursing_project"))
@Api(tags = "项目管理")
public class NursingProjectController extends BaseController {
    @Autowired
    NursingProjectService nursingProjectService;

    @ApiOperation("分页查询项目信息")
    @GetMapping
    public ResponseResult page(String name,  Integer pageNum, Integer pageSize, Integer status) {
        log.info("name:{},page:{},pageSize:{},status:{}", name, pageNum, pageSize, status);
        PageResponse pageResponse = nursingProjectService.page(name, pageNum, pageSize, status);
        return success(pageResponse);
    }

    /**
     * 添加新项目
     *
     * @param nursingProjectDto
     * @return
     */
    @ApiOperation("添加新项目")
    @PostMapping
    public ResponseResult add(@RequestBody NursingProjectDto nursingProjectDto) {
        log.info("新增项目信息:{}", nursingProjectDto);
        nursingProjectService.add(nursingProjectDto);
        return success();
    }

    /**
     * 根据id查询项目信息
     *
     * @param id
     * @return
     */
    @ApiOperation("根据id查询项目信息")
    @GetMapping("/{id}")
    public ResponseResult<NursingProjectVo> selectById(@PathVariable Long id) {
        log.info("根据id查询项目信息:{}", id);
        NursingProjectVo nursingProjectVo = nursingProjectService.selectById(id);
        return success(nursingProjectVo);
    }

    /**
     * 修改项目信息
     *
     * @param nursingProjectDto
     * @return
     */
    @PutMapping
    @ApiOperation("修改项目信息")
    public ResponseResult modify(@RequestBody NursingProjectDto nursingProjectDto) {
        log.info("修改项目信息:{}", nursingProjectDto);
        nursingProjectService.update(nursingProjectDto);
        return success();
    }

    /**
     * 启用,禁用项目
     *
     * @param id
     * @param status
     * @return
     */
    @PutMapping("/{id}/status/{status}")
    @ApiOperation("启用/禁用项目")
    public ResponseResult enableOrDisable(@PathVariable Long id, @PathVariable Integer status) {
        log.info("启用/禁用项目:{},{}", id, status);
        nursingProjectService.enableOrDisable(id, status);
        return success();
    }

    /**
     * 删除项目
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public ResponseResult delete(@PathVariable Long id){
        nursingProjectService.delete(id);
        return success();
    }
    @GetMapping("/all")
    public ResponseResult getAll() {
        List<NursingProjectVo> nursingProjects = nursingProjectService.getAll();
        return success(nursingProjects);
    }
}
